package com.zretc.kscxmz.controller;

import com.github.pagehelper.PageInfo;
import com.zretc.kscxmz.entity.Plan;
import com.zretc.kscxmz.services.PlanService;
import com.zretc.kscxmz.services.impl.PlanServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/Plan")
public class PlanController {
    private static final Logger logger = LoggerFactory.getLogger(PlanController.class);

    @Autowired
    private PlanService planService;



    @RequestMapping("/getPlanInfoById")
    public @ResponseBody
    ResponseEntity getCompanyById(@RequestParam(value = "accountId")Integer accountId,
                                  @RequestParam(value = "workTime")String workTime){
        logger.info("=====通过ID和时间查询便签信息======");
        logger.info("====accountId:"    + accountId);
        logger.info("====workTime:"    + workTime);
        String createTime = "%" + workTime + "%";
        //调用业务层
        Map<String, Object> map = new HashMap<>();
        map.put("accountId",accountId);
        map.put("createTime",createTime);
        List<Plan> planInfoById = planService.getPlanInfoById(map);
        if(planInfoById !=null && planInfoById.size()!=0){
            return  new ResponseEntity(planInfoById, HttpStatus.OK);
        }
        return new ResponseEntity(null, HttpStatus.NO_CONTENT);
    }



    @RequestMapping("/addPlanInfo")
    public @ResponseBody
    int addPlanInfo(@RequestParam(value = "createTime")String createTime,
                    @RequestParam(value = "planContent")String planContent,
                    @RequestParam(value = "planTitle")String planTitle,
                    @RequestParam(value = "accountId")int accountId){
        logger.info("======添加便签信息======");
        logger.info("====createTime:"    + createTime);
        logger.info("====planContent:"  + planContent);
        logger.info("====planTitle:"    + planTitle);
        logger.info("====accountId:"  + accountId);

        //调用业务层
        Map<String, Object> map = new HashMap<>();
        map.put("createTime",createTime);
        map.put("planContent",planContent);
        map.put("planTitle",planTitle);
        map.put("accountId",accountId);
        int companyByPage = planService.addPlanInfo(map);
        logger.info("====addPlanInfo:"   + companyByPage);
        return companyByPage;
    }





}
